package com.weex.app.extend;

import android.view.ViewGroup;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.Component;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.component.WXSlider;
import com.taobao.weex.ui.component.WXVContainer;
import com.taobao.weex.ui.view.WXCirclePageAdapter;
import com.taobao.weex.ui.view.WXCircleViewPager;

@Component(lazyload = false)
public class WXCSlider extends WXSlider {

    public WXCSlider(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
        super(instance, node, parent);
    }

    @JSMethod
    public void showNext() {
        ViewGroup realView = getRealView();
        if (realView instanceof  WXCircleViewPager) {
            WXCircleViewPager viewPager = (WXCircleViewPager) realView;
            WXCirclePageAdapter pageAdapter = (WXCirclePageAdapter)viewPager.getAdapter();
            int first = pageAdapter.getFirst();
            int currentItem = viewPager.getCurrentItem();
            int index = currentItem + 1;

            viewPager.setCurrentItem(first + index, true);
        }
    }

    @JSMethod
    public void showPrev() {
        ViewGroup realView = getRealView();
        if (realView instanceof  WXCircleViewPager) {
            WXCircleViewPager viewPager = (WXCircleViewPager) realView;
            WXCirclePageAdapter pageAdapter = (WXCirclePageAdapter)viewPager.getAdapter();
            int first = pageAdapter.getFirst();
            int currentItem = viewPager.getCurrentItem();
            int index = currentItem - 1;

            viewPager.setCurrentItem(first + index, true);
        }
    }
}
